package com.betty.cscams.controller;

import java.util.List;
import java.util.Map;

import com.betty.cscams.common.http.HttpResult;
import com.betty.cscams.common.page.PageRequest;
import com.betty.cscams.entity.BusSports;
import com.betty.cscams.entity.BusTerm;
import com.betty.cscams.service.BusTermService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import com.betty.cscams.entity.BusSubject;
import com.betty.cscams.service.BusSubjectService;

/**
 * ---------------------------
 *  (BusSubjectController)         
 * ---------------------------
 * 时间：  2022-04-03 12:19:27
 * ---------------------------
 */
@RestController
@RequestMapping("busSubject")
public class BusSubjectController {

	@Autowired
	private BusSubjectService busSubjectService;

	@Autowired
	private BusTermService busTermService;

	/**
	 * 保存
	 * @param record
	 * @return
	 */	
	@PostMapping(value="/save")
	public HttpResult save(@RequestBody BusSubject record) {
		return HttpResult.ok(busSubjectService.save(record));
	}

    /**
     * 删除
     * @param records
     * @return
     */
	@PostMapping(value="/delete")
	public HttpResult delete(@RequestBody List<BusSubject> records) {
//		for (BusSubject record: records) {
//			BusSubject busSubject = busSubjectService.findById(record.getId());
//			BusTerm term = busTermService.findById(busSubject.getTermId());
//			if(term.getStatus() != 1){
//				return HttpResult.error("请选择未开始的学期进行删除");
//			}
//		}
		return HttpResult.ok(busSubjectService.delete(records));
	}

    /**
     * 基础分页查询
     * @param pageRequest
     * @return
     */    
	@PostMapping(value="/findPage")
	public HttpResult findPage(@RequestBody PageRequest pageRequest) {
		return HttpResult.ok(busSubjectService.findPage(pageRequest));
	}
	
    /**
     * 根据主键查询
     * @param id
     * @return
     */ 	
	@GetMapping(value="/findById")
	public HttpResult findById(@RequestParam Long id) {
		return HttpResult.ok(busSubjectService.findById(id));
	}

	@GetMapping(value="/findUsersBySubject")
	public HttpResult findUsersBySubject(Long subjectId) {
		return HttpResult.ok(busSubjectService.findUsersBySubject(subjectId));
	}

	@GetMapping(value="/findSubjectOptions")
	public HttpResult findSubjectOptions(@RequestParam Map<String,Object> params) {
		return HttpResult.ok(busSubjectService.findSubjectOptions(params));
	}

	@GetMapping(value="/findOptions")
	public HttpResult findOptions(@RequestParam Map<String,Object> params) {
		return HttpResult.ok(busSubjectService.findOptions(params));
	}



}
